package com.bonc.modules.item.utils;

import cn.hutool.core.date.DateUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * @author jinlong
 * @date 2021/8/11
 */
@NoArgsConstructor
@Data
public class ChartDate extends Date {

    private ChartDateTypeEnum dateType;

    public ChartDate(ChartDateTypeEnum dateType) {
        super();
        this.dateType = dateType;
    }

    public ChartDate(long date, ChartDateTypeEnum dateType) {
        super(date);
        this.dateType = dateType;
    }

    @Override
    public String toString() {
        switch (dateType) {
            case MONTH:
                return DateUtil.format(this, "yyyy-MM");
            case QUARTER:
                return DateUtil.format(this, "yyyy") + QuarterEnum.getByCode(DateUtil.format(this, "MMdd"));
            case YEAR:
                return DateUtil.format(this, "yyyy");
            default:
                return DateUtil.format(this, "yyyy-MM-dd");
        }
    }


    public static void main(String[] args) {
        long first = DateUtil.parse("20210331", "yyyyMMdd").getTime();
        ChartDate chartDate = new ChartDate(first, ChartDateTypeEnum.QUARTER);
        System.out.println(chartDate);
    }
}
